/**********************************************************************
  The MIT License (MIT)
  Copyright (c) 2012 sunriseyuen

  Permission is hereby granted, free of charge, to any person obtaining
  a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
  THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 ***********************************************************************/

	#define _DEF_CCY_CODE
	#define _ZZDEBUG
	#define _PROJ_DC

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

#region Using directives

using System;
using System.Text;
using System.IO;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Reflection;
using System.Web;
using System.Web.UI;

using Muki.Framework;
using Muki.Framework.UI;
using Muki.Framework.Business;
using Muki.Framework.Util;
using Muki.UserDefine;
using Muki.Entity;
using Dot.StreamObject;

#endregion

namespace Muki.UserPanel
{

	public class UID02801CUI:BaseAction
	{
		public UID02801CUI()
		{
		}

		public override void OnRetrieve(string cDefined_Code)
		{
			_XEventArgs.UDEF_CODE=cDefined_Code;


				UID02801CE _Entity=_UID02801CV.Entity;

				if (cDefined_Code=="LOOKUP")
				{
					if (_UID02801CV.ZZWebOption!="")
					{
						if (_UID02801CV.ZZWebOption!="ZZLOOKUP_ANY_COLUMN")
						{
						  _XEventArgs.Data["LOOKUP_DATA"]=_UID02801CV.ZZLookup;
						  _XEventArgs.Data["LOOKUP_COLUMN_NAME"]=_UID02801CV.ZZWebOption;
							_UID02801CV.ZZPanels["UID02801C","lookup"]=_UID02801CV.ZZLookup;
							_UID02801CV.ZZPanels["UID02801C","column"]=_UID02801CV.ZZWebOption;
						}else{
							string cAnyColumn="";
									cAnyColumn=cAnyColumn+";CQTMITM.CQT_NO";
									cAnyColumn=cAnyColumn+";CQTMITM.CQT_DMI";
									cAnyColumn=cAnyColumn+";CQTMITM.MITEM_NAME01";
									cAnyColumn=cAnyColumn+";CQTMITM.MITEM_NAME02";

						  _XEventArgs.Data["LOOKUP_DATA"]=_UID02801CV.ZZLookup;
						  _XEventArgs.Data["LOOKUP_COLUMN_NAME"]=cAnyColumn;
							_UID02801CV.ZZPanels["UID02801C","lookup"]=_UID02801CV.ZZLookup;
							_UID02801CV.ZZPanels["UID02801C","column"]="ZZLOOKUP_ANY_COLUMN";
						}
					}else{
						 _XEventArgs.Data["LOOKUP_DATA"]=_UID02801CV.ZZLookup;
						 _XEventArgs.Data["LOOKUP_COLUMN_NAME"]="CQT_DMI";
						_UID02801CV.ZZPanels["UID02801C","lookup"] = _UID02801CV.ZZLookup;
						_UID02801CV.ZZPanels["UID02801C","column"] = _UID02801CV.ZZLookup;
					}
				}else if (cDefined_Code=="PICKUP")
				{
					Spliter _PK_Spliter      = new Spliter(_UID02801CV.ZZEventOpts);
					_PK_Spliter.Separator    = '|';
					_PK_Spliter.Separatorb   = '=';
					_PK_Spliter.DecodeBase64 = true;
					_PK_Spliter.Split();

							_Entity.CQT_DMI=_PK_Spliter["CQT_DMI"];
				}else if (cDefined_Code=="ACTIVETAB")
				{
					_UID02801CV.ZZLookup        = _UID02801CV.ZZPanels["UID02801C","lookup"];
					_UID02801CV.ZZWebOption        = _UID02801CV.ZZPanels["UID02801C","column"];
					_UID02801CV.ZZEventStage        = _UID02801CV.ZZPanels["UID02801C","stage"];
					oWebWxfPanel.VIEW_STATUS = _UID02801CV.ZZPanels.getVContexts("UID02801C","view_status");

									_Entity.CQT_NO=_UID02801CV.ZZPanels["UID02801A","XCQT_NO"];
				}

								_Entity.CQT_NO=_UID02801CV.ZZPanels["UID02801A","XCQT_NO"];



				ZZTrace.Debug(ZFILE_NAME,"...123456...DATA_STATUS_CODE1 ");

				UID02801CE _NewEntity=_UID02801CM.Retrieves(_XEventArgs,_Entity);
				
				ZZTrace.Debug(ZFILE_NAME,"...123456...DATA_STATUS_CODE2 "+_NewEntity.DATA_STATUS_CODE);

        foreach (LogisticException tmp in _NewEntity.Exceptions)
        {
						ZZTrace.Debug(ZFILE_NAME,"...123456...Exceptions "+tmp.Name +" - " +tmp.Logistic +" - " +tmp.Refx);
				}
				
				ZZTrace.Debug(ZFILE_NAME,"...123456...Count "+_NewEntity.Exceptions.Count);
						ZZTrace.Debug(ZFILE_NAME,_NewEntity.CQT_DMI);
				if (cDefined_Code=="LOOKUP")
				{
					if (_NewEntity.DATA_STATUS_CODE=="Verified")
					{
						_UID02801CV.Entity=_NewEntity;
						_UID02801CV.ZZVIEW_STATUS_CODE = _UID02801CV.ZZEventStatus;
						_UID02801CV.ZZVIEW_STAGEU_CODE = _UID02801CV.ZZEventStage;
					}
				}else
				{
					if (_NewEntity.DATA_STATUS_CODE=="Verified")
					{
						_UID02801CV.Entity=_NewEntity;
						_UID02801CV.ZZVIEW_STATUS_CODE = _UID02801CV.ZZEventStatus;
						_UID02801CV.ZZVIEW_STAGEU_CODE = _UID02801CV.ZZEventStage;
					}
				}
				_UID02801CV.Exceptions=_NewEntity.Exceptions;
				
		}

		public override void OnDefault()
		{

			UID02801CE _NewEntity=_UID02801CM.Default(_UID02801CV.Entity);

			if (_NewEntity.Exceptions.Count==0)
			{
				this.Trans.Commit();

				_UID02801CV.Entity=_NewEntity;
				_UID02801CV.ZZVIEW_STATUS_CODE = _UID02801CV.ZZEventStatus;
				_UID02801CV.ZZVIEW_STAGEU_CODE = _UID02801CV.ZZEventStage;
			}
			_UID02801CV.Exceptions=_NewEntity.Exceptions;
			
		}

		public override void OnUpdate()
		{
			UID02801CE _NewEntity=_UID02801CM.Update(_UID02801CV.Entity);

			ZZTrace.Debug(ZFILE_NAME,"...123456...DATA_STATUS_CODE2 "+_NewEntity.DATA_STATUS_CODE);

      foreach (LogisticException tmp in _NewEntity.Exceptions)
      {
					ZZTrace.Debug(ZFILE_NAME,"...123456...Exceptions "+tmp.Name +" - " +tmp.Logistic +" - " +tmp.Refx);
			}
			
			ZZTrace.Debug(ZFILE_NAME,"...123456...Count "+_NewEntity.Exceptions.Count);

			if (_NewEntity.Exceptions.Count==0)
			{
				this.Trans.Commit();

				_UID02801CV.Entity=_NewEntity;
				_UID02801CV.ZZVIEW_STATUS_CODE = _UID02801CV.ZZEventStatus;
				_UID02801CV.ZZVIEW_STAGEU_CODE = _UID02801CV.ZZEventStage;
			}
			_UID02801CV.Exceptions=_NewEntity.Exceptions;
			
		}		

		public override void OnAddNew()
		{

			UID02801CE _NewEntity=_UID02801CM.AddNew(_UID02801CV.Entity);

			ZZTrace.Debug(ZFILE_NAME,"...123456...DATA_STATUS_CODE2 "+_NewEntity.DATA_STATUS_CODE);

      foreach (LogisticException tmp in _NewEntity.Exceptions)
      {
					ZZTrace.Debug(ZFILE_NAME,"...123456...Exceptions "+tmp.Name +" - " +tmp.Logistic +" - " +tmp.Refx);
			}
			
			ZZTrace.Debug(ZFILE_NAME,"...123456...Count "+_NewEntity.Exceptions.Count);

			if (_NewEntity.Exceptions.Count==0)
			{
				this.Trans.Commit();

				_UID02801CV.Entity=_NewEntity;
				_UID02801CV.ZZVIEW_STATUS_CODE = _UID02801CV.ZZEventStatus;
				_UID02801CV.ZZVIEW_STAGEU_CODE = _UID02801CV.ZZEventStage;
			}
			_UID02801CV.Exceptions=_NewEntity.Exceptions;
			
		}

		public override void OnDelete()
		{
		
			UID02801CE _NewEntity=_UID02801CM.Delete(_UID02801CV.Entity);
			if (_NewEntity.Exceptions.Count==0)
			{
				this.Trans.Commit();
				//this.Empty();
				this.OnRetrieve("NEXT");

				_UID02801CV.ZZVIEW_STATUS_CODE=_UID02801CV.ZZEventStatus;
				_UID02801CV.ZZVIEW_STAGEU_CODE=_UID02801CV.ZZEventStage;
			}
			_UID02801CV.Exceptions=_NewEntity.Exceptions;
		
		}

		public override void OnUserDef(string cAction_Code,string cDefined_Code)
		{
			_XEventArgs.UDEF_CODE   = cDefined_Code;
			_XEventArgs.Events      = cAction_Code;
			_XEventArgs.STATUS_CODE = _UID02801CV.ZZVIEW_STATUS_CODE;
			_XEventArgs.Sender      = "UID02801C";

			UID02801CE _NewEntity=_UID02801CM.UserDefine(_XEventArgs,_UID02801CV.Entity);

			if (_NewEntity.Exceptions.Count==0)
			{

				_UID02801CV.Entity=_NewEntity;

				_UID02801CV.ZZVIEW_STATUS_CODE = _UID02801CV.ZZEventStatus;
				_UID02801CV.ZZVIEW_STAGEU_CODE = _UID02801CV.ZZEventStage;

				ZZTrace.Debug(ZFILE_NAME,cAction_Code+","+cDefined_Code);
			}
			_UID02801CV.Exceptions=_NewEntity.Exceptions;
		}

		public override void Process()
		{
			try
			{
				checked
				{

					this.Trans = new StreamContext(this.DbName);
					this.Trans.Writeable=true;
					_UID02801CM.Trans=this.Trans;
					_UID02801CM.ZZLiveBlock=_UID02801CV.ZZLiveBlock;
					_UID02801CM.Initialize();
					base.Process();
					
					//this.Trans.Close();

					//this.Trans = new StreamContext(this.DbName);
					
				ZZTrace.Debug(ZFILE_NAME,"Process");
					
				}
			}
			catch (LogisticException e)
			{
				_UID02801CV.Exceptions.Add(e);
				ZZTrace.Error(ZFILE_NAME,e);

				try
				{

					this.Trans.RollBack();
				}
				catch (Exception Ex)
				{
					ZZTrace.Error(ZFILE_NAME,Ex);
				}
			}

			catch (Exception e)
			{
				ZZTrace.Error(ZFILE_NAME,e);
				try
				{
					this.Trans.RollBack();
				}
				catch (Exception)
				{
				}
			}
			finally
			{
				this.Trans.Close();
				ZZTrace.Debug(ZFILE_NAME,"Finally");
			}

		}

		public override void OnInit(HttpContext  objHttpContext)		
		{

			_UID02801CV.OnInit(objHttpContext);
			this.DbName       = _UID02801CV.DbName;
			this.DbName       = _UID02801CV.DbName;
			this.ZZEventArgs  = _UID02801CV.ZZEventArgs;
			this.ZZVIEW_STATUS_CODE     = _UID02801CV.ZZVIEW_STATUS_CODE;
			_UID02801CM.ZZLOGON_ID = _UID02801CV.ZZLOGON_ID;
			_UID02801CV.setValue();
		}

		public override void Render(HtmlTextWriter objTextWriter)
		{

			_UID02801CV.getValue();
			_UID02801CV.Render(objTextWriter);

		}

		const  string ZFILE_NAME   ="UID02801CC";
		const  string MUKI_EDITION ="MIN";

		private	XEventArgs        _XEventArgs = new XEventArgs();
		private UID02801CM      _UID02801CM = new UID02801CM();
		private	WebLookup         objWebLookup  = new WebLookup();
		private WebOption         objWebOption  = new WebOption();
		private WebCellsPanel     oWebWxfPanel  = new WebCellsPanel();
		private ZZCaptions        _Captions     = new ZZCaptions();
		private UID02801CV      _UID02801CV = new UID02801CV();

#region screen element

#endregion
	}
}
